<?php
//(vea http://javascriptsql.sourceforge.net/ )

include_once ("cls_JSBD_Conversor.php");
session_start();

if (isset($_POST["guardarConf"]))
{
    $nomarch=tempnam(sys_get_temp_dir(),"JSB");

    $_SESSION["objJSBDC"]->_conf_arch=$nomarch;
     if (!$_SESSION["objJSBDC"]->Guardar())
    {
        print "ERROR :".$_SESSION["objJSBDC"]->_bd->GetError();
        return false;
    }
    
}
else
    {
         print "guardaConf error";
         exit;
    }
    

$download_file=basename($nomarch);

// place this code inside a php file and call it f.e. "download.php"
$path = sys_get_temp_dir()."/"; // change the path to fit your websites document structure
$fullPath = $path.$download_file;


if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"JSBD.conf\"");
    
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;
// example: place this kind of link into the document where the file download is offered:
// <a href="download.php?download_file=some_file.pdf">Download here</a>

?>
